package navigation.wzg.com.navigation.http;

import android.content.Context;
import android.widget.Toast;

import navigation.wzg.com.navigation.http.Eentity.Sms_Entity;
import navigation.wzg.com.navigation.http.Interface.Sms_http;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by WZG on 2017/10/28.
 */

public class SMSPost {
    public static boolean SmsPost(String phone, String code, final Context context){
        final boolean[] x = {false};
        String appkey = "218254476a474";
        String zone = "86";
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("https://webapi.sms.mob.com/sms/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        Sms_http service = retrofit.create(Sms_http.class);//获取API接口的实现类的实例对象
        Call<Sms_Entity> gsonnn = service.getSms(appkey,phone,zone,code);
        gsonnn.enqueue(new Callback<Sms_Entity>() {
            @Override
            public void onResponse(Call<Sms_Entity> call, Response<Sms_Entity> response) {
                Sms_Entity aaa = response.body();
                Toast.makeText(context, aaa.getStatus(), Toast.LENGTH_SHORT).show();
                if (aaa.getStatus() == 200){
                    x[0] = true;
                }else {
                    x[0] = false;
                }
            }
            @Override
            public void onFailure(Call<Sms_Entity> call, Throwable t) {
                Toast.makeText(context, "请检查您的网络连接", Toast.LENGTH_SHORT).show();
            }
        });
        return x[0];
    }
}
